/*
 * @Description: 
 * @Author: huacong
 * @Date: 2020-05-29 11:07:05
 * @LastEditTime: 2020-09-25 20:36:34
 * @LastEditors: huacong
 */ 
const path = require('path')
const webpack = require('webpack')
const {CleanWebpackPlugin} = require('clean-webpack-plugin')

const dllPath = 'public/static/dll'

module.exports = {
  entry: {
    // 需要提取的库文件
    vueRouter: ['vue-router'],
    antv1: ['@antv/g2'],
    antv2: ['@antv/data-set']
  },
  output: {
    path: path.join(__dirname, dllPath),
    filename: '[name].dll.js',
    // vendor.dll.js中暴露出的全局变量名
    // 保持与 webpack.DllPlugin 中名称一致
    library: '_dll_[name]'
  },
  plugins: [
    // 清除之前的dll文件
    new CleanWebpackPlugin(),
    // 设置环境变量
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify('production')
      }
    }),
    // manifest.json 描述动态链接库包含了哪些内容
    new webpack.DllPlugin({
      path: path.join(__dirname, dllPath, '[name]-manifest.json'),
      // 保持与 output.library 中名称一致
      name: '_dll_[name]',
      context: process.cwd()
    })
  ]
}
